package com.ctg.itrdc.imageconsole.data.dao.impl;

import org.springframework.stereotype.Component;

import com.ctg.itrdc.imageconsole.data.dao.IK8sOperationRecordDao;
import com.ctg.itrdc.imageconsole.data.entity.K8sOperationRecord;
import com.ctg.itrdc.paspsdk.data.dao.impl.BaseDaoImpl;

@Component("k8sOperationRecordDao")
public class K8sOperationRecordDaoImpl extends BaseDaoImpl implements IK8sOperationRecordDao {

	@Override
	public boolean tryOccupyLock(K8sOperationRecord k8sOperationRecord) {
		String sql = "UPDATE K8S_OPERATION_RECORD SET LOCK_VERSION=LOCK_VERSION+1"
				+ ",LAST_UPDATE_TIME=now() WHERE ID=? AND LOCK_VERSION=?";
		int updateCount = this.getJdbcTemplate().update(sql, 
				k8sOperationRecord.getId(),k8sOperationRecord.getLockVersion());
		return updateCount > 0;
	}


}
